// 检测 页面是否有操作
import { logout_timeoutApi } from '@/api/config.js'
import store from '@/store'
import { Logout } from '@/api/manage.js'
export async function monitorfn(v) {
  // console.log(v)
  // 一段时间没有操作自动退出
  let num
  try {
    num = (await logout_timeoutApi('AUTO_LOGOUT_TIME_THRESHOLD')).data.data
  } catch (error) {
    num = 60
  }
  let num2 = num * 60
  document.addEventListener('mousemove', () => {
    num2 = num * 60
    // console.log(num2)
  })
  const time = setInterval(async() => {
    // console.log(v.$route)
    if (v.$route.path !== '/login') {
      num2--
      // console.log(num2)
      if (num2 === 0) {
        await Logout()
        store.dispatch('user/logout')
        v.$router.push(`/login`)
        location.reload()
      }
    } else {
      clearInterval(time)
    }
    // console.log(num2, 'num2--')
  }, 1000)
}
